<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
        $this->display('login');
    }
    public function checkUser()
    {
        $captcha = $_POST['captcha'];
        $verify = new \Think\Verify();
        $user_name = $_POST['username'];
        $psw = $_POST['psw'];
        $manager = M('user');

            //print_r($manager);

        $count = $manager->where("username='%s'", array($user_name))->count();
        
        $data = array();
        if ($count > 0) {
            //代表有这个用户
            $count1 = $manager->where("username='%s' and password=%s", array($user_name, $psw))->count();
            if ($count1 > 0) {
                if ($verify->check($captcha)) {
                    $data['errNo'] = 0;
                    $data['errMsg'] = "登陆成功";
                } else {
                    $data['errNo'] = 3;
                    $data['errMsg'] = "验证码错误";
                }
                // $data['errNo']=0;
                //$data['errMsg']="登陆成功";
            } else {
                $data['errNo'] = 1;
                $data['errMsg'] = "密码错误";
            }
        } else {
            $data['errNo'] = 2;
            $data['errMsg'] = "查无此用户";
        }
        $this->ajaxReturn($data);

    }
    public function verify(){
        $config = array(
            'fontSize' => 20,
            'length'    =>  4,
            'useNoise'  =>true,

        );
        $Verify =new \Think\Verify($config);
        $Verify->entry();
    }

}
